package com.ljm.common.constants;

import com.ljm.common.util.IpUtils;
import org.slf4j.MDC;

/**
 * @author: ChenHuaMing
 * @Date: 2019/10/21 11:37
 * @Description: 系统常量
 */
public class SysConstants {
    private SysConstants(){}

    /**
     * traceId
     */
    public static final ThreadLocal<String> TRACKID_TL=new InheritableThreadLocal<>();
    /**
     * 客户端ip
     */
    public static final ThreadLocal<String> IP_TL=new InheritableThreadLocal<>();
    /**
     * 当前登录账号
     */
    public static final ThreadLocal<String> LOGIN_NAME_TL=new InheritableThreadLocal<>();

    /**
     * 调用链id
     */
    public static final String LOG_TRACE_ID="traceId";
    /**
     * 服务器ip
     */
    public static final String SERVICE_IP="serviceIP";

    /**
     * 请求ip
     */
    public static final String REQUEST_IP="requestIP";

    public static void intMdc(){
        MDC.put(SysConstants.LOG_TRACE_ID, "startMain");
        MDC.put(SysConstants.SERVICE_IP, IpUtils.getLocalIpAddress());
    }

    public static void clearTrackIdThreadLocal(){
        TRACKID_TL.remove();
    }
    public static void clearIpThreadLocal(){
        IP_TL.remove();
    }
    public static void clearLoginNameThreadLocal(){
        LOGIN_NAME_TL.remove();
    }
}
